<style>
    /* 选择项容器样式 */
    .TK-my-wdscpz-make_collection-items {
        max-height: 400px;
        overflow-y: auto;
        padding: 15px;
        background: #f9f9f9;
        border-radius: 8px;
        margin-top: 15px;
    }

    /* 自定义滚动条 */
    .TK-my-wdscpz-make_collection-items::-webkit-scrollbar {
        width: 6px;
    }

    .TK-my-wdscpz-make_collection-items::-webkit-scrollbar-thumb {
        background: #1E9FFF;
        border-radius: 3px;
    }

    .TK-my-wdscpz-make_collection-items::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 3px;
    }

    /* 选择项样式 */
    .TK-my-wdscpz-make_collection-item {
        background: #fff;
        border-radius: 6px;
        margin-bottom: 8px;
        transition: all 0.3s ease;
        box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    }

    .TK-my-wdscpz-make_collection-item:hover {
        transform: translateX(5px);
        box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    }

    /* 顶部操作栏 */
    .TK-my-wdscpz-make_collection-actions {
        padding: 15px;
        border-bottom: 1px solid #eee;
        display: flex;
        align-items: center;
        justify-content: space-between;
        background: #fff;
        border-radius: 8px 8px 0 0;
    }

    /* 内容布局 */
    .TK-my-wdscpz-make_collection-content {
        padding: 12px;
        display: flex;
        gap: 12px;
        align-items: flex-start;
    }

    /* 缩略图样式 */
    .TK-my-wdscpz-make_collection-thumb {
        width: 100px;
        height: 60px;
        border-radius: 4px;
        object-fit: cover;
        flex-shrink: 0;
    }

    /* 右侧信息区域 */
    .TK-my-wdscpz-make_collection-info {
        flex: 1;
        min-width: 0;
    }

    /* 标题行样式调整 */
    .TK-my-wdscpz-make_collection-title-row {
        display: flex;
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 8px;
    }

    /* 标题文本样式 */
    .TK-my-wdscpz-make_collection-title-text {
        color: #666;
        font-size: 13px;
        margin-left: 5px;
    }

    /* 元信息行 */
    .TK-my-wdscpz-make_collection-meta-row {
        padding-left: 30px; /* 与复选框对齐 */
        display: flex;
        gap: 8px;
    }

    /* 线路标签样式 */
    .TK-my-wdscpz-make_collection-meta {
        font-size: 12px;
        color: #666;
        background: #f0f7ff;
        padding: 2px 8px;
        border-radius: 4px;
        display: inline-block;
    }

    /* 表单样式 */
    .TK-my-wdscpz-make_collection-form.layui-form .layui-form-item {
        margin-bottom: 20px;
    }

    .TK-my-wdscpz-make_collection-form.layui-form .layui-input {
        transition: all 0.3s ease;
    }

    .TK-my-wdscpz-make_collection-form.layui-form .layui-input:focus {
        border-color: #1E9FFF !important;
        box-shadow: 0 0 0 2px rgba(30,159,255,0.1);
    }

    /* 选中计数样式 */
    #TK-my-wdscpz-make_collection-selectedCount {
        color: #1E9FFF;
        font-weight: 500;
    }

    /* 响应式调整 */
    @media screen and (max-width: 768px) {
        .layui-layer.TK-my-wdscpz-make_collection-layer {
            width: 100% !important;
            height: 100% !important;
            top: 0 !important;
            left: 0 !important;
            margin: 0 !important;
            border-radius: 0 !important;
        }

        .TK-my-wdscpz-make_collection-container {
            height: 100%;
            display: flex;
            flex-direction: column;
        }

        .TK-my-wdscpz-make_collection-form.layui-form {
            height: 100%;
            display: flex;
            flex-direction: column;
        }

        .TK-my-wdscpz-make_collection-items {
            flex: 1;
            margin: 10px 0;
        }

        .TK-my-wdscpz-make_collection-thumb {
            width: 80px;
            height: 50px;
        }
    }

    /* Tab 样式 */
    .TK-my-wdscpz-make_collection-tabs {
        display: flex;
        border-bottom: 1px solid #eee;
        margin-bottom: 15px;
    }

    .TK-my-wdscpz-make_collection-tab {
        padding: 10px 20px;
        cursor: pointer;
        position: relative;
        color: #666;
        transition: all 0.3s;
    }

    .TK-my-wdscpz-make_collection-tab.active {
        color: #1E9FFF;
    }

    .TK-my-wdscpz-make_collection-tab.active:after {
        content: '';
        position: absolute;
        bottom: -1px;
        left: 0;
        right: 0;
        height: 2px;
        background: #1E9FFF;
    }

    /* 表单区域样式 */
    .TK-my-wdscpz-make_collection-form-section {
        display: none;
    }

    .TK-my-wdscpz-make_collection-form-section.active {
        display: block;
    }

    /* 差异数据样式 */
    .TK-my-wdscpz-make_collection-diff-content {
        padding: 20px;
    }

    .TK-my-wdscpz-make_collection-diff-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 15px;
        padding: 10px;
        background: #f8f8f8;
        border-radius: 4px;
    }

    /* 移动端适配 */
    @media screen and (max-width: 767px) {
        .TK-my-wdscpz-make_collection-diff-content {
            padding: 10px;
        }
        
        .TK-my-wdscpz-make_collection-diff-header {
            flex-direction: column;
            gap: 10px;
            text-align: center;
        }
    }
</style>

<script>
    // 将 handleImageLoad 函数移到全局作用域
    window.handleImageLoad = function(imgElement) {
        const line = imgElement.getAttribute('data-line');
        if (line === '2') {
            // 确保 loadBackgroundImage 函数可用
            if (typeof loadBackgroundImage === 'function') {
                loadBackgroundImage(imgElement.src, imgElement);
            } else {
                console.error('loadBackgroundImage function not found');
            }
        }
    };

    // 制作收藏集
    function make_collection() {
        /**
         * 制作收藏集
         * 1. 获取收藏夹项目列表并转换成JSON遍历
         * 2. 列表中cover和url不需要域名,保留格式可参考为: url: /archives/112568/  cover: /archives/112568.jpg
         * 3. 然后弹出输入框,输入收藏集名称,小于等于10字, 然后首先像后端发送请求,后端返回一个tkid, api: api/not_login/collection/item/create/,POST请求,表单数据提交,参数:name(小于等于10字
), 服务器会返回: 
         * {
                "status": "0",
                "data": {
                    "tkid": "520e54a8-e2fc-4a01-b18e-4364ef160986",
                    "name": "超级好看的收藏夹",
                    "visit_count": 0,
                    "created_at": "2025-02-12 06:13:59"
                }
            }
        - 让用户选择想要收藏的数据,也可以一键全部收藏
         * 4. 后端返回tkid后,将tkid和项目列表发送给后端, api: api/not_login/collection/item/create/,POST请求,表单数据提交,参数:tkid,title,url(不需要加域名,示例值:
/archives/112568/), cover(不需要加域名,示例值: /archives/112568.jpg), line(示例值:
2,要先获取出当前线路,然后再匹配当前线路), 服务器会返回
         * {
                "status": 0,
                "data": {
                    "id": 2,
                    "tkid": "520e54a8-e2fc-4a01-b18e-4364ef160986",
                    "title": "巨乳性感小女友 身材苗条对着镜头被大黑屌爆操 一脸娇羞的样子更显诱惑 直接被操尿喷啦",
                    "url": "/archives/112568/",
                    "cover": "/upload_01/xiao/20250205/2025020520403639534.jpeg",
                    "line": 2,
                    "created_at": "2025-02-12 06:37:57"
                }
            }
         */
        console.log('制作收藏集');

        // 1. 获取本地存储的收藏数据
        const records = JSON.parse(localStorage.getItem(localStorageKey) || '[]');
        
        if (records.length === 0) {
            layer.msg('收藏夹为空，请先添加收藏', {
                icon: 2,
                time: 2000
            });
            return;
        }

        // 2. 处理数据格式
        const processedRecords = records.map(item => {
            const urlObj = new URL(item.url);
            const pathUrl = urlObj.pathname;
            const coverObj = new URL(item.cover);
            const pathCover = coverObj.pathname;  // 这里只保存路径用于后续提交
            const line = item.line.replace('line', '');

            return {
                title: item.title,
                url: pathUrl,
                cover: pathCover,  // 保存路径用于提交
                coverUrl: item.cover,  // 保存完整URL用于显示
                line: parseInt(line),
                selected: true
            };
        });

        // 3. 打开选择弹窗
        layer.open({
            type: 1,
            title: '创建收藏集',
            area: ['500px', '600px'],
            skin: 'TK-my-wdscpz-make_collection-layer',
            content: `
                <div class="TK-my-wdscpz-make_collection-container">
                    <div class="TK-my-wdscpz-make_collection-form layui-form" style="padding: 20px;">
                        <div class="TK-my-wdscpz-make_collection-tabs">
                            <div class="TK-my-wdscpz-make_collection-tab active" data-tab="auto">自动创建</div>
                            <div class="TK-my-wdscpz-make_collection-tab" data-tab="manual">手动输入</div>
                            <div class="TK-my-wdscpz-make_collection-tab" data-tab="diff">差异数据</div>
                        </div>

                        <!-- 自动创建表单 -->
                        <div class="TK-my-wdscpz-make_collection-form-section active" data-section="auto">
                            <div class="layui-form-item">
                                <label class="layui-form-label">收藏集名称</label>
                                <div class="layui-input-block">
                                    <input type="text" id="TK-my-wdscpz-make_collection-name-auto" 
                                           class="layui-input" 
                                           placeholder="请输入收藏集名称(不超过10字)"
                                           maxlength="10">
                                </div>
                            </div>
                        </div>

                        <!-- 手动输入表单 -->
                        <div class="TK-my-wdscpz-make_collection-form-section" data-section="manual">
                            <div class="layui-form-item">
                                <label class="layui-form-label">TKID</label>
                                <div class="layui-input-block">
                                    <input type="text" id="TK-my-wdscpz-make_collection-tkid" 
                                           class="layui-input" 
                                           placeholder="请输入TKID">
                                </div>
                            </div>
                        </div>

                        <!-- 差异数据表单 -->
                        <div class="TK-my-wdscpz-make_collection-form-section" data-section="diff">
                            <div class="layui-form-item">
                                <label class="layui-form-label">TKID</label>
                                <div class="layui-input-block">
                                    <input type="text" 
                                           id="TK-my-wdscpz-make_collection-diff-tkid" 
                                           class="layui-input" 
                                           placeholder="请输入TKID">
                                </div>
                                <div class="layui-input-block" style="margin-top: 10px;">
                                    <button class="layui-btn" onclick="checkDiffData()">查看差异</button>
                                </div>
                            </div>
                            
                            <!-- 差异数据列表 -->
                            <div id="TK-my-wdscpz-make_collection-diff-list" style="display: none;">
                                <div class="TK-my-wdscpz-make_collection-diff-header">
                                    <span>发现 <span id="diffCount">0</span> 条差异数据</span>
                                    <button class="layui-btn layui-btn-normal" onclick="submitDiffData()">提交差异数据</button>
                                </div>
                                <div class="TK-my-wdscpz-make_collection-items" id="diffItems"></div>
                            </div>
                        </div>

                        <div class="TK-my-wdscpz-make_collection-actions">
                            <input type="checkbox" 
                                   lay-filter="TK-my-wdscpz-make_collection-selectAll" 
                                   id="TK-my-wdscpz-make_collection-selectAll" 
                                   title="全选/取消全选" 
                                   checked>
                            <span>已选择: <span id="TK-my-wdscpz-make_collection-selectedCount">${processedRecords.length}</span>/${processedRecords.length}</span>
                        </div>

                        <div class="TK-my-wdscpz-make_collection-items">
                            ${processedRecords.map((item, index) => `
                                <div class="TK-my-wdscpz-make_collection-item">
                                    <div class="TK-my-wdscpz-make_collection-content">
                                        <img class="TK-my-wdscpz-make_collection-thumb" 
                                             src="${item.line === 2 ? '' : item.coverUrl}"  // 线路2先不设置src
                                             data-src="${item.coverUrl}"  // 保存原始URL
                                             alt="${item.title}"
                                             data-line="${item.line}"
                                             data-index="${index}">
                                        <div class="TK-my-wdscpz-make_collection-info">
                                            <div class="TK-my-wdscpz-make_collection-title-row">
                                                <input type="checkbox" 
                                                       lay-filter="TK-my-wdscpz-make_collection-item"
                                                       class="TK-my-wdscpz-make_collection-checkbox"
                                                       data-index="${index}"
                                                       ${item.selected ? 'checked' : ''}>
                                                <span class="TK-my-wdscpz-make_collection-title-text">
                                                    ${item.title.length > 10 ? item.title.substring(0, 10) + '...' : item.title}
                                                </span>
                                            </div>
                                            <div class="TK-my-wdscpz-make_collection-meta-row">
                                                <div class="TK-my-wdscpz-make_collection-meta">线路${item.line}</div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            `).join('')}
                        </div>
                    </div>
                </div>
            `,
            btn: ['确定创建', '取消'],
            success: function(layero, index) {
                // 重新渲染 layui 表单
                layui.form.render();
                
                // 绑定全选事件
                layui.form.on('checkbox(TK-my-wdscpz-make_collection-selectAll)', function(data) {
                    const isChecked = data.elem.checked;
                    layero.find('.TK-my-wdscpz-make_collection-checkbox').each(function() {
                        $(this).prop('checked', isChecked);
                    });
                    processedRecords.forEach(item => item.selected = isChecked);
                    layui.form.render('checkbox');
                    updateSelectedCount();
                });

                // 绑定单个选择事件
                layui.form.on('checkbox(TK-my-wdscpz-make_collection-item)', function(data) {
                    const index = $(data.elem).data('index');
                    processedRecords[index].selected = data.elem.checked;
                    updateSelectedCount();
                    // 更新全选框状态
                    const allChecked = processedRecords.every(item => item.selected);
                    layero.find('#TK-my-wdscpz-make_collection-selectAll').prop('checked', allChecked);
                    layui.form.render('checkbox');
                });

                function updateSelectedCount() {
                    const selectedCount = processedRecords.filter(item => item.selected).length;
                    layero.find('#TK-my-wdscpz-make_collection-selectedCount').text(selectedCount);
                }

                // 在弹窗打开后处理线路2的图片
                layero.find('.TK-my-wdscpz-make_collection-thumb').each(function() {
                    const $img = $(this);
                    const line = $img.data('line');
                    const src = $img.data('src');
                    
                    if (line === 2) {
                        loadBackgroundImage(src, this);
                    } else {
                        $img.attr('src', src);
                    }
                });

                // 添加 tab 切换功能
                layero.find('.TK-my-wdscpz-make_collection-tab').on('click', function() {
                    const tab = $(this).data('tab');
                    
                    // 切换 tab 样式
                    layero.find('.TK-my-wdscpz-make_collection-tab').removeClass('active');
                    $(this).addClass('active');
                    
                    // 切换表单区域
                    layero.find('.TK-my-wdscpz-make_collection-form-section').removeClass('active');
                    layero.find(`.TK-my-wdscpz-make_collection-form-section[data-section="${tab}"]`).addClass('active');
                });
            },
            yes: async function(index, layero) {
                // 获取当前激活的 tab
                const activeTab = layero.find('.TK-my-wdscpz-make_collection-tab.active').data('tab');
                let tkid;

                // 获取选中的项目
                const selectedItems = processedRecords.filter(item => item.selected);
                if (selectedItems.length === 0) {
                    layer.msg('请至少选择一个项目', {icon: 2});
                    return;
                }

                try {
                    // 自动创建模式
                    if (activeTab === 'auto') {
                        const name = layero.find('#TK-my-wdscpz-make_collection-name-auto').val().trim();
                        if (!name) {
                            layer.msg('请输入收藏集名称', {icon: 2});
                            return;
                        }

                        // 先创建收藏集获取 tkid
                        const createResponse = await axios.post(`${window.location.origin}/api/not_login/collection/create/`, {
                            name: name
                        });

                        if (createResponse.data.status !== 0) {  // 改为数字 0，而不是字符串 "0"
                            layer.msg('创建收藏集失败：' + createResponse.data.message, {icon: 2});
                            return;
                        }

                        tkid = createResponse.data.data.tkid;
                    } else {
                        // 手动输入模式
                        tkid = layero.find('#TK-my-wdscpz-make_collection-tkid').val().trim();
                        if (!tkid) {
                            layer.msg('请输入TKID', {icon: 2});
                            return;
                        }
                    }

                    // 显示加载提示
                    const loadingIndex = layer.msg('正在创建收藏集...', {
                        icon: 16,
                        shade: 0.3,
                        time: 0
                    });

                    try {
                        // 批量提交选中的项目
                        const submitPromises = selectedItems.map(item => 
                            axios.post(`${window.location.origin}/api/not_login/collection/item/create/`, {
                                tkid: tkid,
                                title: item.title,
                                url: item.url,
                                cover: item.cover,
                                line: item.line
                            })
                        );

                        // 等待所有请求完成
                        await Promise.all(submitPromises);

                        // 关闭加载提示和所有弹窗
                        layer.closeAll();

                        // 显示 TKID 复制框
                        layer.open({
                            type: 1,
                            title: '收藏集创建成功',
                            area: ['350px', 'auto'],
                            content: `
                                <div style="padding: 20px;">
                                    <div style="margin-bottom: 15px;">
                                        <p style="color: #FF5722; margin-bottom: 10px;">请妥善保管以下 TKID，关闭后将不再显示：</p>
                                        <div style="background: #f5f5f5; padding: 10px; border-radius: 4px; word-break: break-all;">
                                            ${tkid}
                                        </div>
                                    </div>
                                    <div style="text-align: center;">
                                        <button class="layui-btn layui-btn-sm" onclick="copyTkid('${tkid}')">
                                            复制 TKID
                                        </button>
                                    </div>
                                    <div style="margin-top: 15px; font-size: 12px; color: #999;">
                                        提示：您可以使用此 TKID 在"查看收藏集"功能中查看收藏的内容
                                    </div>
                                </div>
                            `,
                            success: function(layero) {
                                // 添加复制成功的回调
                                window.copyTkid = function(text) {
                                    const input = document.createElement('input');
                                    input.value = text;
                                    document.body.appendChild(input);
                                    input.select();
                                    document.execCommand('copy');
                                    document.body.removeChild(input);
                                    
                                    layer.msg('复制成功', {
                                        icon: 1,
                                        time: 1000
                                    });
                                }
                            }
                        });

                    } catch (error) {
                        // 关闭加载提示
                        layer.close(loadingIndex);
                        // 显示错误信息
                        layer.msg(error.response?.data?.message || '创建失败：' + error.message, {
                            icon: 2,
                            time: 2000
                        });
                    }

                } catch (error) {
                    // 显示错误信息
                    layer.msg(error.response?.data?.message || '创建失败：' + error.message, {
                        icon: 2,
                        time: 2000
                    });
                }
            }
        });
    }

    // 切换到差异数据tab
    function switchTab(tab) {
        // 移除所有 tab 的 active 类
        document.querySelectorAll('.TK-my-wdscpz-make_collection-tab').forEach(t => {
            t.classList.remove('active');
        });
        
        // 给当前 tab 添加 active 类
        document.querySelector(`.TK-my-wdscpz-make_collection-tab[data-tab="${tab}"]`).classList.add('active');
        
        // 隐藏所有 section
        document.querySelectorAll('.TK-my-wdscpz-make_collection-form-section').forEach(s => {
            s.classList.remove('active');
        });
        
        // 显示当前 section
        document.querySelector(`.TK-my-wdscpz-make_collection-form-section[data-section="${tab}"]`).classList.add('active');
    }

    // 添加 tab 点击事件监听
    document.addEventListener('click', function(e) {
        const tab = e.target.closest('.TK-my-wdscpz-make_collection-tab');
        if (tab) {
            const tabName = tab.getAttribute('data-tab');
            switchTab(tabName);
        }
    });

    // 检查差异数据
    async function checkDiffData() {
        const tkid = document.getElementById('TK-my-wdscpz-make_collection-diff-tkid').value.trim();
        if (!tkid) {
            layer.msg('请输入TKID', {icon: 2});
            return;
        }

        try {
            // 获取服务器数据
            const response = await axios.get(`${window.location.origin}/api/not_login/collection/item/list/`, {
                params: { tkid }
            });

            if (response.data.status !== 0) {
                layer.msg('获取数据失败，请重新输入TKID', {icon: 2});
                return;
            }

            // 获取本地数据
            const localData = JSON.parse(localStorage.getItem(localStorageKey) || '[]');
            
            // 找出差异数据
            const serverData = response.data.data.map(item => ({
                title: item.title,
                line: `line${item.line}` // 添加 "line" 前缀
            }));

            // 使用 title 和 line 组合作为唯一标识进行比对
            const serverIdentifiers = new Set(
                serverData.map(item => `${item.title}_${item.line}`)
            );

            const diffData = localData.filter(item => 
                !serverIdentifiers.has(`${item.title}_${item.line}`)
            );

            // 显示差异数据
            renderDiffData(diffData);

        } catch (error) {
            layer.msg('检查差异失败：' + error.message, {icon: 2});
        }
    }

    // 渲染差异数据
    function renderDiffData(diffData) {
        const diffList = document.getElementById('TK-my-wdscpz-make_collection-diff-list');
        const diffItems = document.getElementById('diffItems');
        const diffCount = document.getElementById('diffCount');

        if (diffData.length === 0) {
            layer.msg('没有发现差异数据', {icon: 1});
            diffList.style.display = 'none';
            return;
        }

        diffCount.textContent = diffData.length;
        diffList.style.display = 'block';

        diffItems.innerHTML = diffData.map((item, index) => `
            <div class="TK-my-wdscpz-make_collection-item">
                <div class="TK-my-wdscpz-make_collection-content">
                    <img class="TK-my-wdscpz-make_collection-thumb" 
                         src="${item.cover}" 
                         data-src="${item.cover}"
                         data-line="${item.line.replace('line', '')}"
                         alt="${item.title}">
                    <div class="TK-my-wdscpz-make_collection-info">
                        <div class="TK-my-wdscpz-make_collection-title-row">
                            <input type="checkbox" 
                                   class="diff-item-checkbox" 
                                   checked 
                                   data-index="${index}">
                            <span class="TK-my-wdscpz-make_collection-title-text">${item.title}</span>
                        </div>
                        <div class="TK-my-wdscpz-make_collection-meta-row">
                            <span class="TK-my-wdscpz-make_collection-meta">线路${item.line}</span>
                            <span class="TK-my-wdscpz-make_collection-meta">${formatTime(item.timestamp)}</span>
                        </div>
                    </div>
                </div>
            </div>
        `).join('');

        // 处理线路2的图片
        diffItems.querySelectorAll('img[data-line="2"]').forEach(img => {
            loadBackgroundImage(img.dataset.src, img);
        });
    }

    // 提交差异数据
    async function submitDiffData() {
        const tkid = document.getElementById('TK-my-wdscpz-make_collection-diff-tkid').value.trim();
        if (!tkid) {
            layer.msg('请先输入TKID', {icon: 2});
            return;
        }

        // 获取选中的差异数据
        const checkboxes = document.querySelectorAll('.diff-item-checkbox:checked');
        if (checkboxes.length === 0) {
            layer.msg('请选择要提交的数据', {icon: 2});
            return;
        }

        try {
            // 先获取服务器数据
            const response = await axios.get(`${window.location.origin}/api/not_login/collection/item/list/`, {
                params: { tkid }
            });

            if (response.data.status !== 0) {
                layer.msg('获取数据失败，请重新输入TKID', {icon: 2});
                return;
            }

            const localData = JSON.parse(localStorage.getItem(localStorageKey) || '[]');
            // 获取差异数据
            const diffData = localData.filter(item => {
                const serverData = response.data.data.map(sItem => ({
                    title: sItem.title,
                    line: `line${sItem.line}`
                }));
                const serverIdentifiers = new Set(
                    serverData.map(sItem => `${sItem.title}_${sItem.line}`)
                );
                return !serverIdentifiers.has(`${item.title}_${item.line}`);
            });
            
            // 根据选中的checkbox获取对应的差异数据
            const selectedData = Array.from(checkboxes).map(cb => {
                const index = parseInt(cb.dataset.index);
                return diffData[index];
            });

            // 显示加载提示
            const loadingIndex = layer.msg('正在提交数据...', {
                icon: 16,
                shade: 0.3,
                time: 0
            });

            // 批量提交选中的项目
            for (const item of selectedData) {
                try {
                    // 处理 URL - 移除域名部分
                    const urlPath = new URL(item.url).pathname;
                    
                    // 处理 cover - 移除域名部分
                    const coverPath = new URL(item.cover, window.location.origin).pathname;
                    
                    await axios.post(`${window.location.origin}/api/not_login/collection/item/create/`, {
                        tkid: tkid,
                        title: item.title,
                        url: urlPath,
                        cover: coverPath,
                        line: item.line.replace('line', '')
                    });
                    
                    // 每提交一条数据就显示进度
                    layer.msg(`已提交 ${selectedData.indexOf(item) + 1}/${selectedData.length}`, {
                        icon: 16,
                        time: 1000
                    });
                } catch (error) {
                    console.error('提交失败的数据:', item);
                    throw error;
                }
            }

            // 关闭加载提示
            layer.close(loadingIndex);
            layer.msg('提交成功', {icon: 1});

            // 重新检查差异
            checkDiffData();

        } catch (error) {
            layer.msg('提交失败：' + error.message, {icon: 2});
        }
    }
</script>